import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import('@/pages/1-dashboard/index'),
      meta: { title: '首页', icon: '1-shouyei' }
    }]
  },

  {
    path: '/column',
    component: Layout,
    redirect: '/column',
    children: [{
      path: 'index',
      name: 'Column',
      component: () => import('@/pages/2-column/index'),
      meta: { title: '栏目管理', icon: '2-lanmu' }
    }]
  },
  {
    path: '/production',
    component: Layout,
    redirect: '/production',
    children: [{
      path: 'index',
      name: 'Production',
      component: () => import('@/pages/3-production/index'),
      meta: { title: '产品管理', icon: '3-chanpin' }
    }]
  },
  {
    path: '/bill',
    component: Layout,
    redirect: '/bill',
    name: 'Bill',
    meta: { title: '账单管理', icon: '4-zhangdan' },
    children: [
          {
            path: 'guke',
            name: 'Guke',
            component: () => import('@/pages/4-bill/1-guke/index'),
            meta: { title: '顾客账单', icon: '' }
          },
          {
            path: 'yuangong',
            name: 'Yuangong',
            component: () => import('@/pages/4-bill/2-yuangong/index'),
            meta: { title: '员工账单', icon: '' }
          },
          {
            path: 'xitong',
            name: 'Xitong',
            component: () => import('@/pages/4-bill/3-xitong/index'),
            meta: { title: '系统账单', icon: '' }
          }
        ]
  },
  {
    path: '/order',
    component: Layout,
    children: [
      {
        path: 'index',
        name: 'Order',
        component: () => import('@/pages/5-order/index'),
        meta: { title: '订单管理', icon: '5-dingdan' }
      },
      {
        path: 'detail',
        hidden: true,
        name: 'OrderDetail',
        component: () => import('@/pages/5-order/details'),
      },
    ]
  },
  // {
  //   path: '/customer',
  //   component: Layout,
  //   redirect: '/customer',
  //   children: [{
  //     path: 'index',
  //     name: 'Customer',
  //     component: () => import('@/pages/6-customer/index'),
  //     meta: { title: '顾客管理', icon: '6-guke' }
  //   }]
  // },
    // 顾客管理
    {
      path: '/customer',//一级路由
      component: Layout,
      children: [{//一级路由对应的子路由
        path: 'index',
        name: 'Customer',
        component: () => import('@/pages/6-customer/index'),//@指的是当前src目录下
        meta: { title: '顾客管理', icon: '6-guke' }
      },
      {
        path:'detail',
        hidden:true,
        name:'CustomerDetail',
        component:()=>import('@/pages/6-customer/detail')
      }
    ]
  },
  {
    path: '/staff',
    component: Layout,
    redirect: '/staff',
    children: [{
      path: 'index',
      name: 'Staff',
      component: () => import('@/pages/7-staff/index'),
      meta: { title: '员工管理', icon: '7-yuangong' }
    }]
  },
   // 角色权限
   {
    path: '/role',//一级路由
    component: Layout,
    meta:{ title:'角色权限',icon:'11-geren'},
    children: [{//一级路由对应的子路由
      path: 'customer',
      name: 'RoleCustomer',
      component: () => import('@/pages/role/customer'),//@指的是当前src目录下
      meta: { title: '角色管理', icon: 'table' }
    },
    {
      path: 'roles',
      name: 'RoleRoles',
      component: () => import('@/pages/role/roles'),//@指的是当前src目录下
      meta: { title: '用户管理', icon: 'table' }
    },
    {
      path: 'privilege',
      name: 'RolePrivilege',
      component: () => import('@/pages/role/privilege'),//@指的是当前src目录下
      meta: { title: '权限管理', icon: 'table' }
    }
]
  },
  {
    path: '/journal',
    component: Layout,
    redirect: '/journal',
    children: [{
      path: 'index',
      name: 'Journal',
      component: () => import('@/pages/8-journal/index'),
      meta: { title: '日志管理', icon: '8-rizhi' }
    }]
  },
  {
    path: '/rotation',
    component: Layout,
    redirect: '/rotation',
    children: [{
      path: 'index',
      name: 'Rotation',
      component: () => import('@/pages/9-rotation/index'),
      meta: { title: '轮播管理', icon: '9-lunbo' }
    }]
  },
  // 审核大厅 路由
  {
    path: '/examine',
    component: Layout,
    redirect: '/examine',
    name: 'Examine',
    meta: { title: '审核大厅', icon: '2-lanmu' },
    children: [
      {
        path: 'sourceComment',
        name: 'SourceComment',
        component: () => import('@/pages/examine/sourceComment'),
        meta: { title: '资讯评论', icon: 'carousel' },
      },
      {
        path: 'orderComment',
        name: 'OrderComment',
        component: () => import('@/pages/examine/orderComment'),
        meta: { title: '订单评论', icon: 'carousel' },
      },
      {
        path: 'authentication',
        name: 'Authentication',
        component: () => import('@/pages/examine/authentication'),
        meta: { title: '实名认证', icon: 'carousel' },
      },
      {
        path: 'accountChange',
        name: 'AccountChange',
        component: () => import('@/pages/examine/accountChange'),
        meta: { title: '账户变更', icon: 'carousel' },
      },
    ],
  },
  // 网站咨询 路由
  {
    path: '/websource',
    component: Layout,
    redirect: '/websource',
    name: 'Websource',
    meta: { title: '网站资讯', icon: '5-dingdan' },
    children: [
      {
        path: 'category',
        name: 'Category',
        component: () => import('@/pages/webSource/category'),
        meta: { title: '资讯分类', icon: 'carousel' },
      },
      {
        path: 'categoryInfo',
        name: 'CategoryInfo',
        component: () => import('@/pages/webSource/categoryInfo'),
        meta: { title: '资讯信息', icon: 'carousel' },
      },
    ],
  },
  {
    path: '/system',
    component: Layout,
    redirect: '/system',
    children: [{
      path: 'index',
      name: 'System',
      component: () => import('@/pages/10-system/index'),
      meta: { title: '系统配置', icon: '10-xitong' }
    }]
  },
  {
    path: '/personal',
    component: Layout,
    redirect: '/personal',
    children: [{
      path: 'index',
      name: 'Personal',
      component: () => import('@/pages/11-personal/index'),
      meta: { title: '个人信息', icon: '11-geren' }
    }]
  },
  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
